<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>Web-Signed Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" href="websigned2.ico">
</head>

<body>

<%@ page import="java.util.*,java.text.*,apps.Events"%>

<div class="banner">
<h1><a href="websignedteam.html"><img src="webimage.jpg"
	border="0" alt=""> </a>Welcome To Your Personal Calendar: <i><%=session.getAttribute("use")%></i></h1>
<hr>
</div>
<div class="logout"><a href="/Calendar/Login.jsp">Log Out </a></div>
<%
	String[] months = { "January", "February", "March", "April", "May",
			"June", "July", "August", "September", "October",
			"November", "December" };

	int dom[] = { 31, 28, 31, /* jan, feb, mar */
	30, 31, 30, /* apr, may, jun */
	31, 31, 30, /* jul, aug, sep */
	31, 30, 31 /* oct, nov, dec */
	};

	Calendar today = Calendar.getInstance();
	int m = Integer.parseInt(session.getAttribute("month").toString());
	int y = Integer.parseInt(session.getAttribute("year").toString());

	if (m < 0) {
		m = today.get(Calendar.MONTH);
		session.setAttribute("month", m);
	} else {
		m = Integer.parseInt(session.getAttribute("month").toString());
	}

	if (y < 0) {
		y = today.get(Calendar.YEAR);
		session.setAttribute("year", y);
	} else {
		y = Integer.parseInt(session.getAttribute("year").toString());
	}

	String change = new String();
	change = request.getParameter("month");

	if (change == null) {
		request.setAttribute("month", 1);
		change = new String("hi");
	} else {
		switch (Integer.parseInt(change)) {
		case 0:
			m = m - 1;
			break;
		case 1:
			m = m + 1;
			break;
		}

		switch (m) {
		case 12:
			m = 0;
			y = y + 1;
			break;
		case -1:
			m = 11;
			y = y - 1;
			break;
		}
	}
	session.setAttribute("month", m);
	session.setAttribute("year", y);

	String nom = months[m];
%>
<%
	Vector events = (Vector) session.getAttribute("info.value");
	Events[] event = new Events[events.size()];

	int j = 0;
	while (j < events.size()) {
		event[j] = (Events) events.elementAt(j);
		j++;
	}
%>

<div class="create">
<h3>Create an event</h3>

<a href="EventForm.jsp">
<button class = "submit">Add Event</button>
</a><br><br>
<a href="EventForm.jsp?edit=1">
<button class = "submit">Edit Event</button></a><br><br>
</div>
<div class="agenda">
<%
	if (request.getParameter("event") != null) {
		int when = Integer.parseInt(request.getParameter("event")
				.toString());
				session.setAttribute("when",when);
%><h3 class = "agenda">Agenda for the <%=event[when].getStart().substring(8, 10)%>
<%
	int tense = Integer.parseInt(event[when].getStart().substring(
				8, 10));
		switch (tense) {
		case 1:
		case 21:
		case 31:
%><%=" st"%> <%
 	break;
 		case 2:
 		case 22:
 %><%=" nd"%> <%
 	break;
 		case 3:
 		case 23:
 %><%=" rd"%> <%
 	break;
 		default:
 %><%=" th"%> <%
 	break;
 		}
 %>
</h3>

<p class = "no_space_p">At time:</p>
<%
	Date actual = new Date(event[when].getStart());
		Date test = new Date();
		for (int a = 0; a < event.length; a++) {
			test = new Date(event[a].getStart());
			if (test.getYear() == actual.getYear()
					&& test.getMonth() == actual.getMonth()
					&& test.getDay() == actual.getDay()

			) {
%><a href="Calendar.jsp?event=<%=a%>"><%=test.getHours() + ":"
								+ test.getMinutes() + ":" + test.getSeconds()%></a><br>
<%
	}
		}
%>



<h4 class ="agenda_heads">Description of the event</h4> 
<span id="oringe"><%="Starts: "%></span><%=new Date(event[when].getStart()).getHours()+":"+new Date(event[when].getStart()).getMinutes()%> <br>
<span id="oringe"><%="Ends: "%></span><%=new Date(event[when].getEnd()).getHours()+":"+new Date(event[when].getEnd()).getMinutes()%> <br>
<textarea id="event_desc" name="title" cols="" rows="" readonly>
<%=event[when].getDesc()%></textarea>

<h4 class ="agenda_heads">People invited</h4>

<%
	for (int l = 0; l < event[when].getParties().size(); l++) {
%><%=(String) event[when].getParties().elementAt(l)%><br>
<%
	}
%> <%
 	}
 %>
</div>


<div id="Table">
<a href="Calendar.jsp?month=0"><img border="0"
	src="Minus.jpg" id="sign" alt=""></a> <strong class="Month">
<%=nom + " " + y%> </strong> <a href="Calendar.jsp?month=1"><img border="0"
	src="Plus.jpg" id="sign" alt=""></a>
	

<table class="Ctable">
	<tr>
		<th id="yesyoucan">Sun</th>
		<th id="yesyoucan">Mon</th>
		<th id="yesyoucan">Tue</th>
		<th id="yesyoucan">Wed</th>
		<th id="yesyoucan">Thu</th>
		<th id="yesyoucan">Fri</th>
		<th id="yesyoucan">Sat</th>
	</tr>
	<%
		GregorianCalendar cal = new GregorianCalendar(y, m, 1);
		int leadSpaces = cal.get(Calendar.DAY_OF_WEEK) - 1;
	%>
	<tr>
		<%
			for (int i = 0; i < leadSpaces; i++) {
		%>
		<td id="orange"></td>
		<%
			}

			int daysInMonth = dom[m];

			boolean done = false;
			for (int i = 1; i <= daysInMonth; i++) {
		%>
		<td id="yesyoucan">
		<%
			Date date = new Date();
				done = false;
				for (int k = 0; k < event.length; k++) {

					date = new Date(event[k].getStart());
					if ((date.getDate() == i) && (date.getMonth() == m)
							&& ((1900 + date.getYear()) == y)
							&& (done == false)) {
		%><a href="Calendar.jsp?event=<%=Integer.toString(k)%>"><%=i%></a>
		<%
			done = true;
					}
				}
				if (done == false) {
		%><%=i%> <%
 	}
 		if ((leadSpaces + i) % 7 == 0) {
 %>
		</td>
	</tr>
	<tr>
		<%
			}

			}
		%>

	</tr>
</table>
</div>



</body>
</html>